          SUBROUTINE (MAT OE.VARS, ADD.LINES)
** Version# 10 - 08/31/2009 - 11:29am - EJO - main

*** Subroutine - OE.PROD.REL
*-------------------------------------------------------------------------*
*** This routine will allow the user to edit the tag along screen for this
*** product. In addition, the user can use this screen to add products to
*** the order in the recommended quantities or to override the recommended
*** products quantities and add to the order. In addition, the user can
*** access the alternate items screen to add alternates of the products.
*-------------------------------------------------------------------------*
*** Parameters
*** OE.VARS   - Common Order Entry Variables                        [IN]
*** ADD.LINES - Lines to add to the order upon exit                 [OUT]
*-------------------------------------------------------------------------*
*** Common
*** LED and LD
*-------------------------------------------------------------------------*

          $INCLUDE CC OE.EQUATES

          SCREEN

          GOSUB INIT

          IF OID%[1,1] = 'T' OR OID%[1,1] = 'P' THEN
             PRINT @(62,5):''
          END

          IF VIEW.ONLY% THEN
             PRINT @(2,0):BLINK$:'View Only':NORM$
          END

          * Check for any errors on entering this screen. If the errors
          * exist then return.
          GOSUB CHECK.ENTRY.ERRORS
          IF ERR.MSG THEN
             GOSUB FINISH
             RETURN
          END

          * Build the header information
          GOSUB HEADER

          * Get the data to display in the table
          OE.PROD.REL.GET OID,GEN,QSIGN,LD(1),'RELATED',,,PARENT.ADDL,,,DISP.DATA,DISP.ADDL
          LINE.CT = DCOUNT(DISP.DATA,AM)
          REL.PNS = RAISE(PARENT.ADDL<1,4>)

          * Load all the hotkeys
          GOSUB LOAD.HOTKEYS

          * Display the table data
          GOSUB DISPLAY

          LINE = 1; MOVE = 0; LASTKEY = 0; QUIT = NO; F12 = NO
*-------------------------------------------------------------------------*
MOVENEXT: *** Standard handle of movement

          IF QUIT THEN GOTO FILEIT
          NEWOK = (LINE <= LINE.CT)
          DNOK  = (LINE <  LINE.CT)

          PARSEMOVE COL,LINE,COLS,LINE.CT,ROWS,DNOK,NEWOK

          * If this is a new line first enter the tag along product.
          IF LINE > LINE.CT THEN COL = 2

          IF VIEW.ONLY% THEN COL = 1

          ON COL GOTO IN.ORD.QTY,IN.TAG,IN.TYPE
*-------------------------------------------------------------------------*
IN.ORD.QTY:*** Allow a user to input the order quantity
           *** of this tag along. The Order Quantity will sometimes display
           *** as a row of "*" instead of a number. This happens when the
           *** user has updated the quantity on the order such that the
           *** order quantity per parent is not a whole numer.

          ORD.QTY = DISP.DATA<LINE,1>
          IF DISP.DATA<LINE,8> THEN ORD.QTY = 'L';* List item

IN$$2:    INPV ORD.QTY,9,LINE,7,'N0'
          IF QUIT THEN GOTO FILEIT
          IF CHANGED THEN
             IF NOT(NUM(ORD.QTY)) THEN ORD.QTY = UPCASE(ORD.QTY)
             BEGIN CASE
             CASE VIEW.ONLY%
                ERR.MESS ,,'View Only!',YES
                GOSUB DISP.LINE
                GOTO IN.ORD.QTY
             CASE OID%[1,1] = 'S' AND DISP.ADDL<1,LINE>
                * If this product is required then the quantity cannot
                * be lower than recommended.
                REC.QTY = DISP.DATA<LINE,2> * QO
                IF ORD.QTY = 'L' OR (ORD.QTY < REC.QTY) THEN
                   ERR.MSG     = 'Quantity for a required item cannot be'
                   ERR.MSG<2>  = 'below the recommended quantity '
                   ERR.MSG<2> := '(':REC.QTY:').'
                   ERR.MESS 2,2,ERR.MSG,YES
                   GOSUB DISP.LINE
                   GOTO IN.ORD.QTY
                END
             CASE ORD.QTY = 'L'
                LOCATE DISP.DATA<LINE,4,1> IN REL.PNS<1> SETTING DUM THEN
                  ERR.MSG    = 'This product is already on the order'
                  ERR.MSG<2> = 'as a related product.'
                  ERR.MSG<3> = 'Adding it as a List item will remove it.'
                  ERR.MSG<4> = 'Do you want to Continue? (Y/N)'
                  ANS = 'Y'
IN$$1:            INP.PROMPT ANS,ERR.MSG,'YN',1
                  IF NOT(ANS) THEN
                     GOSUB DISP.LINE
                     GOTO IN.ORD.QTY
                  END
                END
             CASE NOT(NUM(ORD.QTY)) AND ORD.QTY # '******'
                GOSUB DISP.LINE
                GOTO IN.ORD.QTY
             CASE TRIM(ORD.QTY) = '' AND DISP.DATA<LINE,2> # ''
                GOSUB DISP.LINE
                GOTO IN.ORD.QTY
             END CASE

             * Update order qty and list addl option
             IF ORD.QTY = 'L' THEN
                DISP.DATA<LINE,1> = 0
                DISP.DATA<LINE,8> = YES
             END ELSE
                DISP.DATA<LINE,1> = ORD.QTY
                DISP.DATA<LINE,8> = NO
             END
             GOSUB DISP.LINE
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
IN.TAG:   *** Enter the tag along product.
          TAG = DISP.DATA<LINE,4,1>
INTAG:    INPV TAG,25,LINE,37,'TPRODUCT;X;1;1',V_'S:VERF.PRD.ID'
          IF QUIT THEN GOTO FILEIT
          IF CHANGED THEN
             * Make sure the related item is not already displayed.
             FOR LCT = 1 TO LINE.CT
                IF LCT = LINE THEN CONTINUE;* skip current line
                IF TAG = DISP.DATA<LCT,4,1> THEN
                   ERR.MSG  = "The related item already exists ":AM
                   ERR.MSG := "for this product."
                   ERR.MESS 2,2,BELL:ERR.MSG,YES
                   GOSUB DISP.LINE
                   GOTO IN.TAG
                END
             NEXT LCT

             * Check if the product entered is the same as the parent.
             IF TAG = PN THEN
                ERR.MSG  = "The related product must be":AM
                ERR.MSG := "different from the parent product."
                ERR.MESS 2,2,BELL:ERR.MSG,YES
                GOSUB DISP.LINE
                GOTO IN.TAG
             END

             * Do not allow a user to override an assigned related item.
             IF DISP.DATA<LINE,2>+0 # 0 THEN
                ERR.MSG = "Do not override an assigned related item."
                ERR.MESS 2,2,BELL:ERR.MSG,YES
                GOSUB DISP.LINE
                GOTO IN.TAG
             END

             * Update tag then prompt for order qty.
             GOSUB UPD.TAG
             GOTO  IN.ORD.QTY
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
UPD.TAG:  *** Get tag data and update display.

          OE.PROD.REL.GET OID,GEN,QSIGN,TAG,'ADDL',,,,,,ONE.DATA,ONE.ADDL

          CNT = DCOUNT(ONE.DATA<1>,VM)
          FOR DCT = 1 TO CNT
             DISP.DATA<LINE,DCT> = ONE.DATA<1,DCT>
          NEXT DCT

          CNT = DCOUNT(ONE.ADDL<1>,VM)
          FOR DCT = 1 TO CNT
             DISP.ADDL<LINE,DCT> = ONE.ADDL<1,DCT>
          NEXT DCT

          LINE.CT = DCOUNT(DISP.DATA,AM)
          GOSUB DISP.LINE

          RETURN
*-------------------------------------------------------------------------*
IN.TYPE:  *** Enter the Type of Tag Along
INTYPE:   INPV DISP.DATA<LINE,3>,63,LINE,6,V_'C:VALID.ADD.TYPES'
          IF QUIT THEN GOTO FILEIT

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INIT:     *** Initialize variables needed in this routine

          * Current Displayed Data
          DISP.DATA = ''

          * Lines to be added to the order based on the user input
          ADD.LINES = ''

          * Parent Part Number
          PN = LD(1)
          * Total Quantity Ordered for the Parent
          QO = LD(4) * QSIGN%

          * Input Parameters Init
          ORD.QTY    = ''
          UNIT.PRICE = ''

          * Vscroll Set Up
          VIEW      = 1
          COL       = 1
          ROW       = 6
          WIDTH     = 79
          ROWS      = 7
          COLS      = 3

          SCREEN.ID = "OE.PROD.REL"
          VSCROLL.DEFINE VIEW,COL,ROW,WIDTH,ROWS,SCREEN.ID
          VSCROLL.SET 1

          OID   = OID%
          GEN   = GEN%
          LDID  = LDID%
          QSIGN = QSIGN%

          RETURN
*-------------------------------------------------------------------------*
LOAD.HOTKEYS: *** Load the Hotkeys for this Screen

          MENU.CLEAR
          MENU.LOAD 2,14,15,5,'R'    ; * Recommended Hotkey
          MENU.LOAD 20,14,7,3,'Q'    ; * Inquiry

          RETURN
*-------------------------------------------------------------------------*
HEADER:   * Sets the display data on the header of this screen. Handles
          * parameter changes when switching screens

          * Get the parent product description and print it
          READV DESC FROM PRDFILE,PN,1 ELSE DESC = ''

          CONVERT VM TO ' ' IN DESC
          PRINT @(20,1):DESC 'L#49'

          PRINT @(20,2):QO

          RETURN
*-------------------------------------------------------------------------*
SUBS:     * Call the appropriate methods for the hotkey based on the
          * version of the screen we are in.
          ON OPTION GOTO RECOMMENDED,INQUIRY
          RETURN
*-------------------------------------------------------------------------*
RECOMMENDED: *** Automatically add the recommended quantity of each
             *** item to the order regardless of order quantities that have
             *** been entered for the recommended or alternate products

          OE.PROD.REL.ADD MAT OE.VARS,QO,DISP.DATA,'RECOMMENDED',ADD.LINES

          RETURN TO FILEIT
*-------------------------------------------------------------------------*
INQUIRY:  *** Open Inquiry Screen for Product You are on
          PRD.VIEW DISP.DATA<LINE,4,1>,LED(2)<1,GEN%,1>,VIEW.ONLY%
          GET.ALL.PRD LED(2)<1,GEN%,1>,PN,QSIGN%

          RETURN
*-------------------------------------------------------------------------*
DISPLAY:  *** Redisplay the necessary data

          * Clear Your VSCROLL
          VCLR 1

          * Count the number of items and display each line
          LINE.CT = DCOUNT(DISP.DATA,AM)
          FOR LINE = 1 TO LINE.CT
             GOSUB DISP.LINE
          NEXT LINE

          RETURN
*-------------------------------------------------------------------------*
DISP.LINE:*** Display line.

          IF DISP.DATA<LINE,2> = '' THEN
             REC.QTY = ''
          END ELSE
             REC.QTY = DISP.DATA<LINE,2> * QO
          END

          * If list item display 'L' in order qty column
          IF DISP.DATA<LINE,8> THEN
             ORD.QTY = 'L'
          END ELSE
             ORD.QTY = DISP.DATA<LINE,1>
          END

          SELL.PRC = DISP.DATA<LINE,6>
          IF SELL.PRC # '' THEN
             SELL.PRC = OCONV(SELL.PRC,'MR3')
          END

          VPRINT  0,LINE,REC.QTY             "L#7"  ;* req qty
          VPRINT  9,LINE,ORD.QTY             "L#7"  ;* ord qty
          VPRINT 17,LINE,DISP.DATA<LINE,5>   "R#7"  ;* avail
          VPRINT 25,LINE,DISP.DATA<LINE,4,2> "L#37" ;* desc
          VPRINT 63,LINE,DISP.DATA<LINE,3>   "L#6"  ;* type
          VPRINT 70,LINE,SELL.PRC            "R#8"  ;* price

          RETURN
*-------------------------------------------------------------------------*
ADD.PRODUCTS:*** Set up the ADD.LINES variable to contain the lines that
             *** have been added as a result of the updates made on this
             *** order.

          IF ADD.LINES = '' THEN
             OE.PROD.REL.ADD MAT OE.VARS,QO,DISP.DATA,,ADD.LINES
          END

          RETURN
*-------------------------------------------------------------------------*
FILEIT:   *** If the user just quits, then don't do anything. Otherwise,
          *** add the specified order quantity of each recommended product
          *** or alt item to the order.

          IF NOT(F12) AND NOT(VIEW.ONLY%) THEN
             PRD.CT = DCOUNT(DISP.DATA,AM)
             FOR PCT = 1 TO PRD.CT
                IF DISP.DATA<PCT,1> # 0 THEN CONTINUE
                ERR.MSG = ''
                IF DISP.ADDL<1,PCT> AND OID%[1,1] = 'S' THEN
                   ERR.MSG = 'Must Enter a Quantity for Required Product'
                END
                IF ERR.MSG THEN
                   ERR.MESS 2,2,ERR.MSG,YES
                   LINE = PCT
                   GOTO IN.ORD.QTY
                END
             NEXT PCT

             * If we are exiting out of standard mode, add the products to
             * the order.
             GOSUB ADD.PRODUCTS
          END

          * If we are in standard mode, close the window
FINISH:   QUIT = NO
          F12 = NO
          WINDOW.CLOSE

          RETURN
*-------------------------------------------------------------------------*
CHECK.ENTRY.ERRORS: *** Check Errors

          ERR.MSG = ''

          IF LED(8)<1,GEN%> THEN
             ERR.MSG  = 'Cannot Modify Related Item After':AM
             ERR.MSG := 'Order Has Been Invoiced.'
             ERR.MESS 2,2,ERR.MSG,YES
          END

          RETURN
*-------------------------------------------------------------------------*
!EJO~08/31/09~11:29
